#include "precompiled.h"
#include "prsTest_Frm.h"
using namespace prsTestFrm;

//
void prsTestFrm::TestGeometry()
{
  char *S =
  "width=3 height=parent direct=vert wAlign=left hAlign=top\r\n"
  ";"
  ;

  svl::TMem Mem; Mem.Add((BYTE*)S,lstrlen(S));
  snt::text::TContext Context; Context.Text() = Mem;

  prs::TNodeFrmGeom Value,ValueCopy;
  svl::TVariant VValue = &Value;

  prs::TRuleFrmGeom RFrmGeom(Context/*,VValue*/);
  snt::TRule        RTest;
  snt::TAlter       A1Test,A2Test;
  
  snt::text::TSequence T(Context);
  snt::TReturn         Return;

  //         |-------------->|
  // RTest ->|-> RFrmGeom ->|-> ";" --> Return
  //         |<--------------|

  RTest
  | A1Test.New()
  ;

  A1Test
  | RFrmGeom.New() & A2Test.New()
  | A2Test.New()
  ;

  A2Test
  | T.New(";") & Return.New()
  | A1Test.New()
  ;
  
  //svl::TMessageModal(RTest.GetGraphInfo(""));

  if (RTest.Execute())
  {
    //Value.OldChildren.Array.NewAndCopyAttrTo(ValueCopy.OldChildren.Array);
    ValueCopy.CopyAttrFrom(&Value);
    svl::TMessageModal(svl::TString("Normal")
      << "\r\nText:\r\n"  << Context.Text().GetInfo() 
      << "\r\nNodes:\r\n" << Value.GetInfoAsString()
      << "\r\nCopy:\r\n"  << ValueCopy.GetInfoAsString()
    );
  }
  else 
  { 
    svl::TMessageModal(svl::TString("Errors") 
      << "\r\n" << Context.GetErrorsInfo()
      << "\r\nNodes:\r\n"  << Value.GetInfoAsString()
    );
  }
}

//
void prsTestFrm::TestFont()
{
  char *S =
  "font ( name=\"sss\" height=1 /*style=italic,bold*/ /*color = 1,2,4*/ ) \r\n"
  ";"
  ;

  svl::TMem Mem; Mem.Add((BYTE*)S,lstrlen(S));
  snt::text::TContext Context; Context.Text() = Mem;

  frm::TFont Value;
  svl::TVariant VValue = &Value;

  prs::TRuleFrmFont RFont(Context,VValue);
  snt::TRule        RTest;
  snt::TAlter       A1Test,A2Test;
  
  snt::text::TSequence T(Context);
  snt::TReturn         Return;

  //         |---------->|
  // RTest ->|-> RFont ->|-> ";" --> Return
  //         |<----------|

  RTest
  | A1Test.New()
  ;

  A1Test
  | RFont.New() & A2Test.New()
  | A2Test.New()
  ;

  A2Test
  | T.New(";") & Return.New()
  | A1Test.New()
  ;
  
  //svl::TMessageModal(RTest.GetGraphInfo(""));

  if (RTest.Execute())
  {
    svl::TMessageModal(svl::TString("Normal")
      << "\r\nText:\r\n"  << Context.Text().GetInfo() 
      //<< "\r\nNodes:\r\n" << Value.GetAttrInfo()
    );
  }
  else 
  { 
    svl::TMessageModal(svl::TString("Errors") 
      << "\r\n" << Context.GetErrorsInfo()
      //<< "\r\nNodes:\r\n"  << Value.GetAttrInfo()
    );
  }
}

//
void prsTestFrm::TestFrmStringStyle()
{
  char *S =
  "string( \r\n"
  "  normal(  \r\n"
  "    font(name=\"Arial\" height=10 color=20,170,0 style=bold,italic)  \r\n"
  "    filler() \r\n"
  "  ) \r\n"
  "  focused(  \r\n"
  "    font(name=\"Arial\" height=10 color=200,0,0  style=bold,italic)  \r\n"
  "  ) \r\n"
  ") \r\n"
  ;

  svl::TMem Mem; Mem.Add((BYTE*)S,lstrlen(S));
  snt::text::TContext Context; Context.Text() = Mem;

  prs::TNodeStyle ParentNode;
  svl::TVariant VParentNode = &ParentNode;

  prs::TRuleFrmStringStyle Rule(Context,VParentNode);
  TRule(Context,ParentNode,Rule).Execute();
}

//
void prsTestFrm::TestFrmString()
{
  char *S =
  "string s1( \r\n"
  "  value = \"qwerty\"  \r\n"
  "  \"_asdfg\"  \r\n"
  "  //style=w \r\n"
  ") \r\n"
  ;

  svl::TMem Mem; Mem.Add((BYTE*)S,lstrlen(S));
  snt::text::TContext Context; Context.Text() = Mem;

  prs::TNode ParentNode;
  svl::TVariant VParentNode = &ParentNode;
  snt::TRuleEmpty RChildren;
/*
  prs::TRuleFrmString Rule(Context,VParentNode,RChildren);
  //svl::TMessageModal(RTest.GetGraphInfo(""));
  TRule(Context,ParentNode,Rule).Execute();
*/  
}

//
void prsTestFrm::TestMain()
{
  prs::TNodeFrmControl ParentNode;
  frm::control::TWindow Win;
  
  snt::text::TContext Context; 
  Context.Text().LoadFromFile(
    "C:\\Documents and Settings\\Sergeyka\\VisualC\\Projects\\Data\\prsTestFrm.txt"
  );

  //char *S =
  //"form f1 \r\n"
  //"  //style = s1  \r\n"
  //"  string (value=\"qwerty_1\") \r\n"
  //"  string (value=\"qwerty_2\") \r\n"
  //;
  //svl::TMem Mem; Mem.Add((BYTE*)S,lstrlen(S));
  //Context.Text = Mem;

  svl::TVariant VParentNode = &ParentNode;
/******  
  prs::TRuleForm Rule(Context,VParentNode);
  //svl::TMessageModal(RTest.GetGraphInfo(""));

  if (TRule(Context,ParentNode,Rule).Execute()) {

    ParentNode.BuildFrmControl(
      prsNodes::TNodeFrmControl::TBuildFrmControl(&Win.Client)
    );

    Win.SetWindowRect(grf::TRect(100,100,600,600),false);
    Win.Show();
    Win.MessagesLoop();
    //Win.Client.DeleteChildren();
  }
*********/  
/*******
  TStyles Styles;
  TForm Form(Styles,Win);
  TPageEvents Ev1(Form);
  TPageControlEvents Ev2(Form);
  TWindowEvents Ev3(Form);
  
  Form.SetRuleWidth (new geometry::TParent());
  Form.SetRuleHeight(new geometry::TParent());
  Win.Client.SetTableOfStyles(&Styles.S1);

  Win.Client.AddChildLast(&Form,false);

  Win.Client.InheritStyle();
  Form.Page1->UpdateVisible(true);
***********/

  //Win.Client.AddChildLast(new frm::control::TStringEdit(Win),true);


}

//
void prsTestFrm::Test()
{
  svl::TWindow MainWin;
  
    TestGeometry();
    //TestFont();

    //TestFrmStringStyle();
    //TestFrmString();
  
  //TestMain();
}
